<!--社区列表-->
<template>
    <div>
            <el-row :gutter="20" class="yx_el_row">
                <el-col :span="4">
                    <el-button type="primary" plain @click="edit(-1,1)">添加</el-button>
                </el-col>
            </el-row>
            <el-table class="yx_table" border :data="volunteerlist">
                <el-table-column prop="index" label="序号" width="100">
                </el-table-column>
                <el-table-column prop="title" label="活动标题" width="180">
                </el-table-column>
                <el-table-column prop="start_date" label="开始时间" width="100">
                </el-table-column>
                <el-table-column prop="end_date" label="截止时间" width="100">
                </el-table-column>
                <el-table-column prop="show_top" label="是否置顶" width="100">
                </el-table-column>
                <el-table-column prop="number_rate" label="所需人数/已报名人数" width="180">
                </el-table-column>
                <el-table-column prop="open_sign" label="是否开启报名" width="180">
                </el-table-column>
                <el-table-column prop="enabled" label="状态" width="100">
                </el-table-column>
                <el-table-column  label="操作">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="编辑" placement="bottom-start">
                            <el-button type="primary" icon="el-icon-edit" @click="edit(scope.row.id,2)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="查看" placement="bottom-start">
                            <el-button type="info" icon="el-icon-notebook-1" @click="edit(scope.row.id,0)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="删除" placement="bottom-start">
                            <el-button type="warning" icon="el-icon-delete" @click="del(scope.row.id)" circle></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
            <Pagination :total_count="total_count" :getList="getList"></Pagination>
    </div>
</template>

<script>
    import Pagination from '@/components/Pagination.vue';
    import { getVolunteerList,delVolunteer } from '@/api/volunteer.js';
    export default {
        name: 'ServiceList',
        inject:['reload'],
        components:{ Pagination },
        data() {
            return {
                volunteerlist:[],
                total_count:0
            }
        },
        methods: {
            getList(current_page,page_size){
                var send_data={
                    api_token:this.$store.getters.getSessionId,
                    current_page:current_page,
                    page_size:page_size
                }
                let that=this;
                getVolunteerList(send_data).then(function(response){
                   if(response.data.code==1){
                     that.volunteerlist=response.data.list;
                     that.total_count=response.data.total_count;
                   }
                })
            },
            edit(id,edit_type){
                this.$router.push({
                    name:'serviceedit',
                    params:{id:id,edit_type:edit_type}
                });
            },
            del(id){
                let that=this;
                //弹框提示
                this.$confirm('确认删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then((e) => {
                    var send_data={
                        api_token : that.$store.getters.getSessionId,
                        id:id
                    };
                    delVolunteer(send_data).then(function(response){
                        let type=response.data.code==1?'success':'error';
                        let msg=response.data.code==1?'删除成功':'删除失败'
                        that.$message({
                            message:msg,
                            duration:1200,
                            type:type,
                            onClose:function(e){
                                that.reload();
                            }
                        });
                    })
                })
            }
        },
        created() {
            this.getList(1,this.$store.state.default_page_size);
        }
    }
</script>

<style>
     @import url('../../../assets/css/table.css');
</style>
